package com.suncp.common;

/**
 * Notice:
 *
 * @author scp
 * @version 1.0
 * @date 2021/3/21
 * @since 1.0
 */
public enum RespCodes {
    /**
     * TX-接口通信模块
     */
    TX0000("0000","响应成功"),
    TX9999("E9999","系统内部异常"),
    /**
     * 安全校验模块
     */
    E15001("E15001","无效订单号"),
    /**
     * 财务凭证模块
     */
    E16001("E16001","计算销项税时,无效订单信息");

    private String code;
    private String text;

    RespCodes(String code, String text){
        this.code = code;
        this.text = text;
    }

    /**
     * 根据code查询描述：从定义好的枚举项中查找
     * @param code 代码
     * @return String
     */
    public static String explain(String code) {
        for (RespCodes bean : RespCodes.values()) {
            if (bean.code.equals(code)) {
                return bean.text;
            }
        }
        return code;
    }

    public String replace(String params){
        if(this.text == null){
            return "";
        }
        return this.text.replace("%s",params);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    @Override
    public String toString() {
        return "BusiCodeEnum{" +
                "code='" + code + '\'' +
                ", text='" + text + '\'' +
                '}';
    }
}
